package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsAchievement;
import com.cs.cssupplier.domain.CsEnterprise;
import com.cs.cssupplier.mapper.CsWinningResultsMapper;
import com.cs.cssupplier.service.CsAchievementService;
import com.cs.cssupplier.service.CsEnterpriseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsEnterpriseController
 * @Date：2024/11/14 16:47
 * @Filename：CsEnterpriseController
 */
@RestController
@RequestMapping("/enterprise")
public class CsEnterpriseController extends BaseController {
    @Resource
    private CsEnterpriseService csEnterpriseService;
    @Autowired
    private CsWinningResultsMapper mapper;
    /**
     * 查询资质id
     * @param zz_id
     * @return
     */
    @GetMapping(value = "cd/{zz_id}")
    public AjaxResult EnterpriseId(@PathVariable("zz_id")Long zz_id){
        System.out.println(AjaxResult.success(csEnterpriseService.selectEnterprisezzId(zz_id)));
        return AjaxResult.success(csEnterpriseService.selectEnterprisezzId(zz_id));
    }

    /**
     * 查询资质信息
     * @param csEnterprise
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsEnterprise csEnterprise){
        startPage();
        List<CsEnterprise> list=csEnterpriseService.selectEnterpriseList(csEnterprise);
        return getDataTable(list);
    }

    /**
     * 添加资质信息
     * @param csEnterprise
     * @return
     */
    @PostMapping
    public AjaxResult insertEnterprise(@RequestBody CsEnterprise csEnterprise){
        return toAjax(csEnterpriseService.addEnterprise(csEnterprise));
    }

    /**
     * 修改资质信息
     * @param csEnterprise
     * @return
     */
    @PutMapping
    public AjaxResult updateEnterprise(@RequestBody CsEnterprise csEnterprise){
        Long userid = SecurityUtils.getLoginUser().getUserid();
        Long sipplierByUserId = mapper.getSipplierByUserId(userid);//这才是供应商id
        csEnterprise.setHid(sipplierByUserId);
        System.out.println(csEnterpriseService.updateEnterprise(csEnterprise));
        return toAjax(csEnterpriseService.updateEnterprise(csEnterprise));
    }

    /**
     * 批量删除资质信息
     * @param zz_id
     * @return
     */
    @DeleteMapping("/{zz_id}")
    public AjaxResult deleteEnterprise(@PathVariable Long [] zz_id){
        return toAjax(csEnterpriseService.deleteListEnterprise(zz_id));
    }
}
